<?php
namespace Home\Controller;
use Think\Controller;
class VersionController extends CommonController {
    public function data_list(){
        $limit = I("pageSize", 30, "intval"); 
        $page = I("pageCurrent", 1, "intval");
        $search_words = I('search_words');
        $condition['ve_value'] = array('like','%'.$search_words.'%');
        $this->assign('search_words',$search_words);
        $version_model = D("Version");
        $count = $version_model->get_count($condition);
        $dataList = $version_model->get_version_list($condition, $limit, $page);
        $this->assign("count",$count);
        $this->assign("dataList",$dataList);
    	$this->display();
    }
    public function operation(){
        $ot = I("ot");
        $ve_id = I("ve_id");
        $version_model = D("Version");
        if($ot==null||$ot==''){
            $ot = $_GET["ot"];
        }
        if($ve_id==null||$ve_id==''){
            $ve_id = $_GET["ve_id"];
        }
        if($ot=='add'&&$ve_id==null){
            if(IS_POST){
                $data['ve_value'] = $_POST["ve_value"];
                $data['ve_retain_idle'] = $_POST["ve_retain_idle"];
                $result = $version_model->add($data);
                if($result){
                    exit(success('成功！',true));
                }else{
                    exit(error('失败！'));
                }
            }else{
                $this->assign("ot",'add');
                $this->display();
            }
        }if($ot=='edit'&&$ve_id!=null){
            if(IS_POST){
                $condition['ve_id'] = $ve_id;
                $data['ve_value'] = $_POST["ve_value"];
                $data['ve_retain_idle'] = $_POST["ve_retain_idle"];
                $result = $version_model->where($condition)->save($data);
                if($result){
                    exit(success('成功！',true));
                }else{
                    exit(error('失败！'));
                }
            }else{
                $condition['ve_id'] = $ve_id;
                $data = $version_model->where($condition)->find();
                $this->assign("ot",'edit');
                $this->assign("data",$data);
                $this->display();
            }
        }else if($ve_id!=null&&$ot=='del'){
            $condition['ve_id'] = $ve_id;
            $result = $version_model->where($condition)->delete();
            if($result){
                exit(success('成功！',false));
            }else{
                exit(error('失败！'));
            }
        }else{
            //exit(error('参数错误！'));
        }
    }
}